﻿<UserControl 
  x:Class="CrackNET.InjectedViewer.Filtering.PropertyFilterGroupView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib"
  x:Name="root"
  >
  <ScrollViewer VerticalScrollBarVisibility="Auto">
    <ItemsControl 
      Grid.IsSharedSizeScope="True"
      ItemsSource="{Binding ElementName=root, Path=FilterGroup.Filters}" 
      >
      <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
          <UniformGrid Columns="2" Rows="3" IsItemsHost="True" />
        </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
      <ItemsControl.ItemTemplate>
        <DataTemplate>
          <Border BorderBrush="LightGray" BorderThickness="0,0,0,1" Margin="4,0" MinWidth="260">
            <StackPanel Margin="0,4" Orientation="Horizontal">
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition SharedSizeGroup="DisplayNameColumn" />
                </Grid.ColumnDefinitions>
                <TextBlock 
                  Text="{Binding Path=DisplayName}" 
                  TextAlignment="Right"
                  VerticalAlignment="Center" 
                  />
              </Grid>
              <ComboBox 
                ItemsSource="{Binding Path=AvailableCriteria, Mode=OneTime}"
                Margin="6,0" 
                SelectedItem="{Binding Path=ActiveCriterion, Mode=TwoWay}"
                Width="110" 
                >
                <ComboBox.ItemTemplate>
                  <DataTemplate>
                    <TextBlock Text="{Binding Path=DisplayName, Mode=OneTime}" />
                  </DataTemplate>
                </ComboBox.ItemTemplate>
              </ComboBox>
              <Grid Width="90">
                <TextBox  x:Name="textBox" Text="{Binding Path=Value, UpdateSourceTrigger=PropertyChanged}" Width="90" KeyDown="textBox_KeyDown" />
                <CheckBox x:Name="checkBox" Width="90" Visibility="Collapsed" VerticalAlignment="Center" />
              </Grid>
              <Button Margin="6,0" Command="{Binding Path=ApplyCommand, Mode=OneTime}" Width="60">Apply</Button>
              <Button 
                Command="{Binding Path=ClearCommand, Mode=OneTime}" 
                Content="X" 
                Cursor="Hand"
                FontFamily="Courier" 
                FontSize="11"
                FontWeight="Bold"  
                Margin="0,0,2,0"
                Padding="0"
                ToolTip="Clear filter"        
                VerticalAlignment="Center" 
                VerticalContentAlignment="Bottom"
                Width="16" Height="16" 
                />
            </StackPanel>
          </Border>

          <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding PropertyType}" Value="{x:Type sys:Boolean}">
              <!-- 
              Setting IsChecked here prevents a binding error from being emitted 
              to the Output window when the property type is not Boolean. 
              -->
              <Setter TargetName="checkBox" Property="IsChecked" Value="{Binding Path=Value}" />
              <Setter TargetName="checkBox" Property="Visibility" Value="Visible" />
              <Setter TargetName="textBox" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
          </DataTemplate.Triggers>
        </DataTemplate>
      </ItemsControl.ItemTemplate>
    </ItemsControl>
  </ScrollViewer>
</UserControl>